package one.stand.config;

import com.alibaba.fastjson.JSONObject;
import com.jmp.autocofiguration.OneOssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 12:54
 */
@Component
public class ExtJsonConfig {
    @Value("${extjson.uploadUrl}")
    private String uploadUrl;
    @Value("${extjson.baseUrl}")
    private String baseUrl;
    @Value("${extjson.wssUrl}")
    private String wssUrl;
    @Autowired
    private OneOssProperties oneOssProperties;

    /**
     * 获取extjson
     *
     * @param appid
     * @param jumpAppId
     * @param jumpName
     * @param companyKey
     * @return
     */
    public JSONObject getExtJSON(String appid, String jumpAppId, String jumpName, String companyKey, String headImg, String myAppName) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("extAppid", appid);
        JSONObject extJSON = new JSONObject();
        extJSON.put("jumpAppId", jumpAppId);
        extJSON.put("jumpName", jumpName);
        extJSON.put("companyKey", companyKey);
        extJSON.put("headImg", headImg);
        extJSON.put("uploadUrl", uploadUrl);
        extJSON.put("baseUrl", baseUrl);
        extJSON.put("wssUrl", wssUrl);
        extJSON.put("ossUrl", oneOssProperties.getUrl());
        jsonObject.put("ext", extJSON);
        jsonObject.put("extEnable", true);
        jsonObject.put("navigateToMiniProgramAppIdList", new String[]{jumpAppId});
        JSONObject windowJson = new JSONObject();
        windowJson.put("navigationBarTitleText", myAppName);
        windowJson.put("navigationStyle", "custom");
        jsonObject.put("window", windowJson);
        return jsonObject;
    }
}
